//
//  ClockSetViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/22.
//

@interface ClockTableCell : UITableViewCell

@end

@implementation ClockTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if(self ==  [super initWithStyle: style reuseIdentifier:reuseIdentifier]){
        
        UILabel *lb = [[UILabel alloc]init];
        lb.text = @"07:00";
        lb.textColor = [UIColor qmui_colorWithHexString:@"#151515"];
        lb.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:lb];
        [lb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(15);
        }];
        
        UILabel *day = [[UILabel alloc]init];
        day.text = @"每天";
        day.textColor = [UIColor qmui_colorWithHexString:@"#888888"];
        day.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:day];
        [day mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(lb.mas_bottom).offset(10);
        }];
        
        UISwitch *sw = UISwitch.new;
        sw.on = YES;
        sw.onTintColor = [UIColor qmui_colorWithHexString:@"#37B0A6"];
        [self.contentView addSubview:sw];
        [sw mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
            make.centerY.equalTo(self.contentView);
        }];
        
    }
    return self;
}

@end


#import "ClockSetViewController.h"
#import "AddClockViewController.h"
@interface ClockSetViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UIView *topBackView;
@property(nonatomic,strong) UITableView *tableView;
@end

@implementation ClockSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setIsHideNavigationBar:YES];
    self.view.backgroundColor = [UIColor qmui_colorWithHexString:@"#F1F4F4"];
    FlexFrameView *view = [[FlexFrameView alloc]initWithFlex:@"ClockSetViewController" Frame:self.view.bounds Owner:self];
    [self.view addSubview:view];
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(15, 100, kScreenWidth - 30, 72)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = UIView.new;
    self.tableView.backgroundColor = UIColorWhite;
    self.tableView.layer.cornerRadius = 15;
    [self.tableView registerClass:[ClockTableCell class] forCellReuseIdentifier:@"ClockTableCell"];
    self.tableView.rowHeight = 72;
    self.tableView.bounces = NO;
    [self.view addSubview:self.tableView];
    
    
    // 加号
    UIButton *addBtn = [[UIButton alloc] init];
    [addBtn setImage:UIImageMake(@"jiance_add") forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
    [self.view insertSubview:addBtn aboveSubview:self.tableView];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-64);
        make.size.equalTo(@(CGSizeMake(48, 48)));
    }];



    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setGradientLayerForTopContainer) name:FLEXDIDLAYOUT object:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ClockTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClockTableCell" forIndexPath:indexPath];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)addBtnClick {
    AddClockViewController * vc = AddClockViewController.new;
    [self.navigationController qmui_pushViewController:vc animated:YES completion:nil];
}


- (void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setGradientLayerForTopContainer {
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = self.topBackView.bounds;
    gl.startPoint = CGPointMake(0.5, 0);
    gl.endPoint = CGPointMake(0.5, 1);
    gl.colors = @[(__bridge id)[UIColor qmui_colorWithHexString:@"#A7B8FF"].CGColor, (__bridge id)[UIColor qmui_colorWithHexString:@"#F1F4F4"].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    UIGraphicsBeginImageContext(self.topBackView.size);
    [gl renderInContext:UIGraphicsGetCurrentContext()];
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.topBackView.backgroundColor = [UIColor colorWithPatternImage:image];

}



@end
